<?php

namespace App\Providers;

use Illuminate\Support\Facades\Session;
use Illuminate\Support\ServiceProvider;
use App\Interfaces\CartService;
use Auth;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        view()->share('SEO',config('seo'));


    }

    /**
     * Register any appliation services.
     *
     * @return void
     */
    public function register()
    {
        //绑定接口和实现
        $this->app->bind('App\Interfaces\PictureService', 'App\Repositories\PictureRepository');
        $this->app->bind('App\Interfaces\CategoryService', 'App\Repositories\CategoryRepository');

        //绑定评论接口和实现
        $this->app->bind('App\Interfaces\CommentService', 'App\Repositories\CommentRepository');

        //广告绑定
        $this->app->bind('App\Interfaces\AdService', 'App\Repositories\AdRepository');

        //积分绑定
        $this->app->bind('App\Interfaces\UserPointLogService', 'App\Repositories\UserPointLogRepository');
        //活动绑定
        $this->app->bind('App\Interfaces\ActivityService', 'App\Repositories\ActivityRepository');
        //品牌绑定
        $this->app->bind('App\Interfaces\BrandService', 'App\Repositories\BrandRepository');

        //绑定订单接口和实现
        $this->app->bind('App\Interfaces\OrderService', 'App\Repositories\OrderRepository');

        //绑定订单接口和实现
        $this->app->bind('App\Interfaces\CollectionService', 'App\Repositories\CollectionRepository');
        $this->app->bind('App\Interfaces\RecommendPositionService', 'App\Repositories\RecommendPositionRepository');

        //绑定商品接口和实现
        $this->app->bind('App\Interfaces\GoodsService', 'App\Repositories\GoodsRepository');
        //搜索
        $this->app->bind('App\Interfaces\SearchKeywordsService', 'App\Repositories\SearchKeywordsRepository');
        //短信
        $this->app->bind('App\Interfaces\SmsService', 'App\Repositories\DayuSmsRepository');



        //个人中心
        $this->app->bind('App\Interfaces\MyService', 'App\Repositories\MyRepository');
        //注册
        $this->app->bind('App\Interfaces\UserService', 'App\Repositories\UserRepository');

        //评论
        $this->app->bind('App\Interfaces\CommentService', 'App\Repositories\CommentRepository');



        //购物车
        $this->app->singleton('App\Interfaces\CartService', function ($app) {
            //虚拟化SESSION_ID,解决代理BUG
            $session_id = Session::get('session_id');
            if ($session_id==''){
                Session::put('session_id',Session::getId());
                Session::save();
                $session_id = Session::get('session_id');
            }
            $user = Auth::user();
            if ($user){
                $type='USER';
                $reference_id =$user->id;
            }else{
                $type='SESSION';
                $reference_id = $session_id;
            }
            return new \App\Repositories\CartRepository($type,$reference_id);
        });


        //用户收货地址
        $this->app->bind('App\Interfaces\AddressService', 'App\Repositories\AddressRepository');


        //用户
        $this->app->bind('App\Interfaces\UserCollectionService', 'App\Repositories\UserCollectionRepository');

        //商铺
        $this->app->bind('App\Interfaces\ShopService', 'App\Repositories\ShopRepository');


        //订单
        $this->app->bind('App\Interfaces\OrderService', 'App\Repositories\OrderRepository');

        //物流
        $this->app->bind('App\Interfaces\ShippingService', 'App\Repositories\ShippingRepository');


        //收货地址
        $this->app->bind('App\Interfaces\AreaService', 'App\Repositories\AreaRepository');


        //用户浏览记录
        $this->app->singleton('App\Interfaces\UserViewHistoryService', function ($app) {
            //虚拟化SESSION_ID,解决代理BUG
            $session_id = Session::get('session_id');
            if ($session_id==''){
                Session::put('session_id',Session::getId());
                Session::save();

                $session_id = Session::get('session_id');
            }
            $user = Auth::user();
            if ($user){
                $user_id =$user->id;
            }else{
                $user_id =0;
            }
            return new \App\Repositories\UserViewHistoryRepository($user_id,$session_id);
        });



        //收货地址
        $this->app->bind('App\Interfaces\SolrService', 'App\Repositories\SolrRepository');

        //库存更新
        $this->app->bind('App\Interfaces\StockService', 'App\Repositories\StockRepository');

        //库存操作日志
        $this->app->bind('App\Interfaces\GoodsStockHistoryService', 'App\Repositories\GoodsStockHistoryRepository');


        //售后流程（退货）
        $this->app->bind('App\Interfaces\RefundGoodsService', 'App\Repositories\RefundGoodsRepository');

        //售后（退货）流程操作记录
        $this->app->bind('App\Interfaces\RefundGoodsOperationRecordService', 'App\Repositories\RefundGoodsOperationRecordRepository');

        //订单商品服务
        $this->app->bind('App\Interfaces\OrderGoodsService', 'App\Repositories\OrderGoodsRepository');

        //验证码
        $this->app->bind('App\Interfaces\CaptchaService', 'App\Repositories\CaptchaRepository');

        //关键词
        $this->app->bind('App\Interfaces\KeywordsService', 'App\Repositories\KeywordsRepository');

        //推关订单
        $this->app->bind('App\Interfaces\PushTarrifService', 'App\Repositories\PushTarrifRepository');

        //产品sku
        $this->app->bind('App\Interfaces\ProductSkuService', 'App\Repositories\ProductSkuRepository');

        //优惠券服务
        $this->app->bind('App\Interfaces\CouponService', 'App\Repositories\CouponRepository');

        //限时折扣服务
        $this->app->bind('App\Interfaces\DiscountService', 'App\Repositories\DiscountRepository');

        //口令优惠服务
        $this->app->bind('App\Interfaces\PasswordCouponService', 'App\Repositories\PasswordCouponRepository');

        //订单派单服务
        $this->app->bind('App\Interfaces\OrderDistributesService', 'App\Repositories\OrderDistributesRepository');


    }
}
